package com.jiyun.service.impl;

import com.jiyun.entity.Game;
import com.jiyun.dao.GameDao;
import com.jiyun.service.GameService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * (Game)表服务实现类
 *
 * @author makejava
 * @since 2020-11-12 14:04:38
 */
@Service("gameService")
public class GameServiceImpl implements GameService {
    @Autowired
    private GameDao gameDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Game queryById(Integer id) {
        return this.gameDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Game> queryAllByLimit(int offset, int limit) {
        return this.gameDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param game 实例对象
     * @return 实例对象
     */
    @Override
    public Game insert(Game game) {
        this.gameDao.insert(game);
        return game;
    }

    /**
     * 修改数据
     *
     * @param game 实例对象
     * @return 实例对象
     */
    @Override
    public Game update(Game game) {
        this.gameDao.update(game);
        return this.queryById(game.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.gameDao.deleteById(id) > 0;
    }

    @Override
    public List<Game> searchGame(String name) {
        return gameDao.searchGame(name);
    }

    @Override
    public Integer checkName(String name) {
        return gameDao.checkName(name);
    }
}